package com.dd.ljzapplication;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

import com.dd.ljzapplication.activity.BarActivity;
import com.dd.ljzapplication.activity.CustomViewActivity;
import com.dd.ljzapplication.activity.DrawActivity;
import com.dd.ljzapplication.activity.EasyTripActivity;
import com.dd.ljzapplication.activity.FPGJActivity;
import com.dd.ljzapplication.activity.HXBankActivity;
import com.dd.ljzapplication.activity.LazyLoadActivity;
import com.dd.ljzapplication.activity.QQBarActivity;
import com.dd.ljzapplication.activity.RecyclerViewActivity;
import com.dd.ljzapplication.activity.RefreshActivity;
import com.dd.ljzapplication.bean.RefreshLoan;
import com.emiage.ddutils.ActivityUtils;
import com.emiage.ddutils.LogUtils;
import com.emiage.ddutils.ScreenUtils;
import com.emiage.ddutils.SystemUtils;
import com.emiage.ddutils.UIUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import base.BaseUtilActivity;


/**
 * 自建项目：
 * 1.版本升级，自动更新
 * 2.沉浸式状态栏
 * 3.recyclerview上拉刷新，下拉加载//ok
 * 4.glide加载图片，Fresco加载图片
 * 5.fragme*-nt懒加载
 * 6.listview和scrollview和viewpager的嵌套
 * 7.apk分包，热更新，插件化加载
 * 8.透明状态栏
 * 9.下载上传，notifation提醒，多个一键上传
 * 10.内存泄漏检测
 * 11.bugly继承
 * 12.crash处理
 * 13.qq软键盘//ok
 * 14.自定义控件：attres 组合控件 和 自定义控件
 * 15.动画
 * 16.主题切换
 * 17.RecyclerView和ScrollView的嵌套
 * 18.带下拉刷新的布局
 */

public class MainActivity extends BaseUtilActivity implements View.OnClickListener {

	private static int sStatusBarHeight;
	private Button mBtn1;
	private Button mBtn2;
	private Button mBtn3;
	private Button mBtn4;
	private Button mBtn5;
	private Button mBtn6;
	private Button mBtn7;
	private Button mBtn8;
	private Button mBtn9;
	private Button mBtn10;


	@Override
	protected int setLayoutID() {
		return R.layout.activity_main;
	}

	@Override
	protected void init() {
		EventBus.getDefault().register(this);
	}

	@Override
	protected void initView() {

		LogUtils.setTag("####");
		int screenHeight = ScreenUtils.getScreenHeight(this);
		int screenWidth = ScreenUtils.getScreenWidth(this);
		int statusHeight = ScreenUtils.getStatusHeight(this);
		LogUtils.i("###", "screenHeight:" + screenHeight + "----dpi:" + UIUtils.px2dip(screenHeight));
		LogUtils.i("###", "screenWidth:" + screenWidth + "----dpi:" + UIUtils.px2dip(screenWidth));
		LogUtils.i("###", "statusHeight:" + statusHeight);
		getStatusBarHeight(this.getWindow());
		LogUtils.i("###", "sStatusBarHeight:" + sStatusBarHeight);

		float height = ScreenUtils.getActionBarHeight(this);
		Log.i("###", "ActionBar：" + height + "");
		float heightDpi = SystemUtils.getHeightDpi();
		float widthDpi = SystemUtils.getWidthDpi();
		LogUtils.i("###", "heightDpi:" + heightDpi);
		LogUtils.i("###", "widthDpi:" + widthDpi);

		//沉浸式状态栏
		mBtn1 = (Button) findViewById(R.id.btn1);
		//glide
		mBtn2 = (Button) findViewById(R.id.btn2);
		//e实贷相关
		mBtn3 = (Button) findViewById(R.id.btn3);
		//recyclerView的Adapter
		mBtn4 = (Button) findViewById(R.id.btn4);
		mBtn5 = (Button) findViewById(R.id.btn5);
		//Fragment懒加载
		mBtn6 = (Button) findViewById(R.id.btn6);
		//版本升级
		mBtn7 = (Button) findViewById(R.id.btn7);
		//QQ空间渐变Action Bar
		mBtn8 = (Button) findViewById(R.id.btn8);
		//自定义控件
		mBtn9 = (Button) findViewById(R.id.btn9);
		//带Header的RecyclerView
		mBtn10 = (Button) findViewById(R.id.btn10);

	}

	@Override
	protected void initActionBar() {

	}

	@Override
	protected void initEvent() {
		if (mBtn1 != null) {
			mBtn1.setOnClickListener(this);
		}
		mBtn2.setOnClickListener(this);
		mBtn3.setOnClickListener(this);
		mBtn4.setOnClickListener(this);
		mBtn5.setOnClickListener(this);
		mBtn6.setOnClickListener(this);
		mBtn7.setOnClickListener(this);
		mBtn8.setOnClickListener(this);
		mBtn9.setOnClickListener(this);
		mBtn10.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.btn1:
				ActivityUtils.startActivity(this, BarActivity.class);
				break;
			case R.id.btn2:
//				ActivityUtils.startActivity(this, GlideActivity.class);
				ActivityUtils.startActivity(this, DrawActivity.class);
				break;
			case R.id.btn3://e实贷相关：recyclerview加载3列图片
				ActivityUtils.startActivity(this, HXBankActivity.class);
				break;
			case R.id.btn4:
				ActivityUtils.startActivity(this, RecyclerViewActivity.class);
//				ActivityUtils.startActivity(this, LogActivity.class);
				break;
			case R.id.btn5:
				ActivityUtils.startActivity(this, EasyTripActivity.class);
				break;
			case R.id.btn6:
				ActivityUtils.startActivity(this, LazyLoadActivity.class);
				break;
			case R.id.btn7:
//				ActivityUtils.startActivity(this, UpdateVersionActivity.class);
				ActivityUtils.startActivity(this, FPGJActivity.class);
			case R.id.btn8:
				ActivityUtils.startActivity(this, QQBarActivity.class);
				break;
			case R.id.btn9:
				ActivityUtils.startActivity(this, CustomViewActivity.class);
				break;
			case R.id.btn10:
				ActivityUtils.startActivity(this, RefreshActivity.class);

				break;
			default:
				break;
		}
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void eventBus(RefreshLoan event) {
		Toast.makeText(this, "event bus", Toast.LENGTH_SHORT).show();
	}

	/**
	 * 公司方法:获取为0
	 *
	 * @param window
	 */
	public static void getStatusBarHeight(Window window) {
		Rect rect = new Rect();
		window.getDecorView().getWindowVisibleDisplayFrame(rect);
		// 状态栏的高度
		sStatusBarHeight = rect.top;
	}
}
